
cmake_minimum_required (VERSION 2.6)

project("kcarddav")

find_package(KDE4 REQUIRED)
find_package(Qt4 REQUIRED)
include(KDE4Defaults)
include(KDE4Macros)
include(FindKDE4Internal)
include(FindKdepimLibs)

# - Find neon

# Look for the header file.
FIND_PATH(NEON_INCLUDE_DIR NAMES neon/ne_socket.h)
MARK_AS_ADVANCED(NEON_INCLUDE_DIR)

# Look for the library.
FIND_LIBRARY(NEON_LIBRARY NAMES neon)
MARK_AS_ADVANCED(NEON_LIBRARY)

# handle the QUIETLY and REQUIRED arguments and set NEON_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(NEON DEFAULT_MSG NEON_LIBRARY NEON_INCLUDE_DIR)

IF(NEON_FOUND)
  SET(NEON_LIBRARIES ${NEON_LIBRARY})
  SET(NEON_INCLUDE_DIRS ${NEON_INCLUDE_DIR})
ELSE(NEON_FOUND)
  SET(NEON_LIBRARIES)
  SET(NEON_INCLUDE_DIRS)
ENDIF(NEON_FOUND)

include_directories(
    ${KDE4_INCLUDES}
    ${QT_INCLUDES}
)

########### set variables #############

# Do not use RPATH, since dependent libraries are in /usr/lib
set(CMAKE_SKIP_RPATH TRUE)

add_definitions(-DKDE_DEFAULT_DEBUG_AREA=5650)  # kresources debug area

if(KCARDDAV_DEBUG)
    set(CMAKE_BUILD_TYPE Debug)
    add_definitions(-DKCARDDAV_DEBUG)  # enables debug output
endif()

set(kcarddav_libs ${KDE4_KDECORE_LIBS}
                  ${KDEPIMLIBS_KABC_LIBS}
                  ${KDEPIMLIBS_KRESOURCES_LIBS}
                  ${NEON_LIBRARIES}
                  )

# ########### next target ###############

set(kabc_carddav_LIB_SRCS   resource.cpp
                            config.cpp
                            preferences.cpp
                            job.cpp
                            download.cpp
                            upload.cpp
)

kde4_add_kcfg_files(kabc_carddav_LIB_SRCS prefsskel.kcfgc)

kde4_add_library(kabc_carddav SHARED ${kabc_carddav_LIB_SRCS})

# add imported target
# add_library(kcarddav_carddav_lib STATIC IMPORTED)
# point the imported target at the real file
#set_target_properties(kcarddav_carddav_lib PROPERTIES IMPORTED_LOCATION libcarddav.a)

target_link_libraries(kabc_carddav  ${kcarddav_libs})

set_target_properties(kabc_carddav PROPERTIES VERSION ${KCARDDAV_VERSION})

install(TARGETS kabc_carddav ${INSTALL_TARGETS_DEFAULT_ARGS})

########### next target ###############

set(kabc_carddav_plugin_PART_SRCS plugin.cpp)

kde4_add_plugin(kabc_carddav_plugin ${kabc_carddav_plugin_PART_SRCS})
# TODO: plugin and shared lib could not have the same name
if (NOT MSVC)
set_target_properties(kabc_carddav_plugin PROPERTIES OUTPUT_NAME kabc_carddav)
endif (NOT MSVC)

target_link_libraries(kabc_carddav_plugin kabc_carddav
                                          ${kcarddav_libs}
                                          )

install(TARGETS kabc_carddav_plugin  DESTINATION ${PLUGIN_INSTALL_DIR})

########### install files ###############

install(FILES ../pkg/kabc_carddav.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kresources/kabc)
